﻿
#region License, Terms and Conditions
//
// MessageService.cs
//
// Authors: Kori Francis <twitter.com/djbyter>
// Copyright (C) 2012 Kori Francis. All rights reserved.
// 
// THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion

namespace Intercom.Core
{
    #region Imports
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    #endregion

    public class MessageService : IntercomApiBase
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="username">The API username to use when accessing the API</param>
        /// <param name="password">The API password to use when accessing the API</param>
        public MessageService(string username, string password)
            : base(username, password)
        { }

        /// <summary>
        /// Gets a user's message thrads. Expects either the email or user_id you used to create the user. 
        /// If a thread_id is specified only that thread will be returned.
        /// </summary>
        /// <returns>The object if successful, null otherwise.</returns>
        public IEnumerable<MessageThread> All(int user_id)
        {
            return GetRequest<List<MessageThread>>("/users/message_threads?user_id={0}", user_id);
        }

        /// <summary>
        /// Gets a user's message thrads. Expects either the email or user_id you used to create the user. 
        /// If a thread_id is specified only that thread will be returned.
        /// </summary>
        /// <returns>The object if successful, null otherwise.</returns>
        public IEnumerable<MessageThread> All(string email)
        {
            return GetRequest<List<MessageThread>>("/users/message_threads?email={0}", email);
        }

        /// <summary>
        /// Gets a user's message thrads. Expects either the email or user_id you used to create the user. 
        /// If a thread_id is specified only that thread will be returned.
        /// </summary>
        /// <returns>The object if successful, null otherwise.</returns>
        public MessageThread Single(string email, int thread_id)
        {
            return GetRequest<MessageThread>("/users/message_threads?email={0}&thread_id={1}", email, thread_id);
        }
    }
}
